
//import WebDriverWait;



import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.*;import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BaseClass{
	static WebDriver driver;
	static BufferedWriter bw = null;
	static BufferedWriter bw1 = null;
	static String htmlname;
	static String objType;
	static String objName;
	static String TestData;
	static String rootPath;
	static int report;


	Date cur_dt = null;
	static String filenamer;
	static String TestReport;
	int rowcnt;
	static String exeStatus = "True";
	static int iflag = 0;
	static int j = 0;

	static String fireFoxBrowser;
	static String chromeBrowser;

	static String result;
	static String dataTablePath = null;
	static int intRowCount = 0;
	@Test
	public void test() throws Exception {


String dataTablePath = "C:/Users/alubana/Google Drive/Framework/Configration/Configration-ProjectAssinment.xls"; 	

          // String dataTablePath="C:/Users/amandeep/Google Drive/Framework/Configration.xls";
		
		String recData[][] = null;
		recData = projectFunction.readData(dataTablePath, "Sheet1");
		String scriptName = null;
		String strResultPath = null;
		for(int i = 1; i <recData.length; i ++){
			String run_NoRun = recData[i][1];

			if(run_NoRun.equalsIgnoreCase("Yes")){
				String testScriptName = recData[i][2];	
				cur_dt = new Date(); 
				DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
				String strTimeStamp = dateFormat.format(cur_dt);
				String ReportsPath ="C:/Users/alubana/Google Drive/Framework/Results/";
				//String ReportsPath = "C:/Users/amandeep/Google Drive/Framework/Results/";


				if (ReportsPath == "") { // if results path is passed as null, by
					// default 'C:\' drive is used
					ReportsPath = "C:\\";
				}

				if (ReportsPath.endsWith("\\")) { // checks whether the path ends with
					// '/'
					ReportsPath = ReportsPath + "\\";
				}

				strResultPath = ReportsPath + "Log" + "/"  + "/" +testScriptName + "/"; 
				htmlname = ReportsPath + "Log" + "/" + "/" + testScriptName + "/" + testScriptName + "_" + strTimeStamp 
						+ ".html";
				File f = new File(strResultPath);
				f.mkdirs();






				bw = new BufferedWriter(new FileWriter(htmlname));

				bw.write("<HTML><BODY><TABLE BORDER=0 CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TABLE BORDER=0 BGCOLOR=BLACK CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TR><TD BGCOLOR=#66699 WIDTH=27%><FONT FACE=VERDANA COLOR=WHITE SIZE=2><B>Test Case Name:</B></FONT></TD><TD COLSPAN=6 BGCOLOR=#66699><FONT FACE=VERDANA COLOR=WHITE SIZE=2><B>"
						+ "TestCase Name" + "</B></FONT></TD></TR>");
				bw.write("<HTML><BODY><TABLE BORDER=1 CELLPADDING=3 CELLSPACING=1 WIDTH=100%>");
				bw.write("<TR COLS=7><TD BGCOLOR=#FFCC99 WIDTH=3%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Row</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Step Name</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Execution Time</B></FONT></TD> "
						+ "<TD BGCOLOR=#FFCC99 WIDTH=10%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Status</B></FONT></TD>"
						+ "<TD BGCOLOR=#FFCC99 WIDTH=47%><FONT FACE=VERDANA COLOR=BLACK SIZE=2><B>Detailed Report</B></FONT></TD></TR>");







				driver = new FirefoxDriver();
System.out.println(testScriptName);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 
		Method testCase = TestScript.class.getMethod(testScriptName);
              //  Method testCase= Test.class.getMethod(testScriptName);
                System.out.println("The name of test case is:"+testCase);
				testCase.invoke(testCase);

				driver.close();
				bw.close();

			}else{
				System.out.println("In confugaration field test script in line number " + i + ", name " + recData[i][2] + " is skipped Execution. ");
			}

		}

	}


	public static void Update_Report(String Res_type,String Action, String result) throws IOException {
		String str_time;
		Date exec_time = new Date();
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
		str_time = dateFormat.format(exec_time);
		if (Res_type.startsWith("Pass")) {
			bw.write("<TR COLS=7><TD BGCOLOR=#EEEEEE WIDTH=3%><FONT FACE=VERDANA SIZE=2>"
					+ (j + 1)
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2>"
					+Action
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2>"
					+ str_time
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2 COLOR = GREEN>"
					+ "Passed"
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=30%><FONT FACE=VERDANA SIZE=2 COLOR = GREEN>"
					+ result + "</FONT></TD></TR>");
			//		writeXl( dataTablePath,  "Sheet1",  intRowCount,  5,  "Pass");
		} else if (Res_type.startsWith("Fail")) {
			exeStatus = "Failed";
			report = 1;
			bw.write("<TR COLS=7><TD BGCOLOR=#EEEEEE WIDTH=3%><FONT FACE=VERDANA SIZE=2>"
					+ (j + 1)
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2>"
					+Action
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2>"
					+ str_time
					+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=10%><FONT FACE=VERDANA SIZE=2 COLOR = RED>"
					+ "<a href= "
					+ filenamer
					+ "  style=\"color: #FF0000\"> Failed </a>"

				+ "</FONT></TD><TD BGCOLOR=#EEEEEE WIDTH=30%><FONT FACE=VERDANA SIZE=2 COLOR = RED>"
				+ result + "</FONT></TD></TR>");

		} 
	}
}

